<?php
namespace app\index\controller;

use think\Controller;
use think\Db;
use app\index\model\AppModel;
class Index extends Controller
{
    public function index()
    {
        //手机跳转手机页面
        if(isMobile()){
            $this->redirect('/index.php/mobile/index');
        }
        $App = new AppModel();
        if($_POST){
            $phone = input('param.phone');
            if($phone){
                if(!checkMobile($phone)){
                    ajaxReturn(-1,'手机号格式错误');
                }
            }else{
                ajaxReturn(-1,'手机号不能为空');
            }
            if($App->checkIsApp(array("app_phone"=>$phone,"DATE_FORMAT(app_time,'%Y-%m-%d')"=>date('Y-m-d')))){
                ajaxReturn(1,'预约成功');
            }
            $data = array(
                'app_phone'=>$phone,
                'app_time'=>date('Y-m-d H:i:s')
            );
            $res = $App->insertAppInfo($data);

            if($res){
                ajaxReturn(1,'预约成功');
            }else{
                ajaxReturn(-1,'预约成功');
            }
        }
        return $this->fetch();
    }
}
